package com.ruoyi.mq;

import com.ruoyi.common.config.datasource.DynamicDataSourceContextHolder;
import com.ruoyi.common.utils.exception.AjaxException;
import com.ruoyi.system.service.other.MqReceiveService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MyListener {

    public static final Logger log = LoggerFactory.getLogger(DynamicDataSourceContextHolder.class);

    @Autowired
    private MqReceiveService mqReceiveService;


    @RabbitListener(queues = "ipay_queue")
    public void msg(String msg) throws IOException {
        log.info("消费者消费消息了："+msg);
        //TODO 这里可以做异步的工作
        try {
            mqReceiveService.Ireceive(msg);
        }catch (Exception e){
            log.warn("产生死信 {} error");
            throw new AjaxException("error");
        }
    }
}
